<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="Comparecimento na Consulta - TAG"/></title>
        <h:outputScript name="bigManage.js" library="js"/>
    </ui:define>

    <ui:define name="content">
        <h:form id="selectionF">
            <p:messages id="msg" autoUpdate="true" showDetail="true"/>
            <h:outputText styleClass="enrollmentName" value="Comparecimento na Consulta"/>
                <div class="input-list">
                <h:outputLabel class="label" for="consentCampaign" value="Campanha: "/>
                <p:selectOneMenu id="consentCampaign" value="#{consultationMB.campaign}" converter="campaignC">
                    <f:selectItems value="#{consultationMB.campaigns}"  var="c" itemLabel="#{c.name}" itemValue="#{c}" />
                    <p:ajax update="consentUnity" process="@this"/>
                </p:selectOneMenu>
                </div>
                <div class="input-list">
                <h:outputLabel class="label" value="Ano: "/>
                <p:spinner value="#{consultationMB.year}" min="#{consultationMB.actualYear-1}" max="#{consultationMB.actualYear}" size="4">
                    <f:validator validatorId="yearV"/>
                    <f:attribute name="minimo" value="#{(consultationMB.actualYear-1).toString()}"/>
                    <f:attribute name="maximo" value="#{(consultationMB.actualYear).toString()}"/>
                    <p:ajax update="consentUnity" process="@this"/>
                </p:spinner>
                </div>
                <div class="input-list">
                <h:outputLabel class="label" for="consentUnity" value="Turma: "/>
                <p:selectOneMenu id="consentUnity" value="#{consultationMB.unity}" label="Campanha Preencher"  converter="unityC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma unidade:"/>
                    <f:selectItems value="#{consultationMB.unityList}" var="u" itemLabel="#{u.name}" itemValue="#{u}"/>
                    <p:ajax update=":patientF" process="@form" listener="#{consultationMB.loadHumansStatus()}"/>
                </p:selectOneMenu>
                </div>
        </h:form>
        <div style="clear:both"></div>
        <br />
        <h:form id="patientF">
            <p:separator rendered="#{consultationMB.humansStatus != null}"/>
            
            <p:dataTable id="patientDT" var="patient" value="#{consultationMB.humansStatus}"
                         rendered="#{consultationMB.humansStatus != null}" rowIndexVar="i">
                <f:facet name="header">Registo de comparecimento a consulta médica</f:facet>

                <p:column headerText="Nome">
                    <h:outputText value="#{patient.element.name}"/>
                </p:column>

                <p:column headerText="Compareceu a consulta?">
                    <center>
                        <p:selectOneButton value="#{patient.status}" onchange="setEdited(this);" converter="booleanC">
                            <f:selectItem itemLabel="Sim" itemValue="${true}"/>
                            <f:selectItem itemLabel="Não" itemValue="#{false}"/>
                        </p:selectOneButton>
                        <h:inputHidden value="#{patient.edited}"/>
                    </center>
                </p:column>
            </p:dataTable>
            
            <p:separator/>

            <p:commandButton action="#{consultationMB.save()}" value="Salvar" rendered="#{consultationMB.humansStatus != null}"/>
        </h:form>
    </ui:define>
</ui:composition>